package com.aaa.ssm.service.impl;

import com.aaa.ssm.dao.TScenicPicDao;
import com.aaa.ssm.entity.TScenicPic;
import com.aaa.ssm.service.TScenicPicService;
import com.aaa.ssm.util.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ fileName:TScenicPicServiceImpl
 * @ description:进去图片的上传
 * @ createTime:2023/4/7 14:10
 * @ version:1.0.0
 */
@Service
public class TScenicPicServiceImpl implements TScenicPicService {
    @Resource
    private TScenicPicDao tScenicPicDao;
    @Resource
    private HttpSession session;
    /**
     * 分装格式化时间类
     * @return
     */
    private static String time(){
        //获取当前时间
        Date date = new Date();
        //实例化格式化时间类
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //format格式化时间
        String format = simpleDateFormat.format(date);
        return format;
    }

    @Override
    public PageInfo queryAll(Page<TScenicPic> page) {
        PageHelper.startPage(page.getPageNo(), page.getPageSize());
        return new PageInfo(tScenicPicDao.queryAll(page.getData()));
    }

    @Override
    public int add(TScenicPic tScenicPic) {
        String userA =(String) session.getAttribute("loginA");
        tScenicPic.setSctime(time());
        tScenicPic.setScrid(userA);
        return tScenicPicDao.add(tScenicPic);
    }

    @Override
    public int update(TScenicPic tScenicPic) {
        String userA =(String) session.getAttribute("loginA");
        tScenicPic.setSctime(time());
        tScenicPic.setScrid(userA);
        return tScenicPicDao.update(tScenicPic);
    }

    @Override
    public int delete(int id) {
        return tScenicPicDao.delete(id);
    }
}
